package com.qf.service.Impl;

import com.qf.entity.User;
import com.qf.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IUserServiceImpl implements IUserService {
    /*模拟注册*/
    private List<User> userList = new ArrayList<>();

    @Override
    public int register(User user) {
        //循环List
        for (User user1 : userList) {
            //判断当前用户是否存在
            if (user1.getUsername().equals(user.getUsername())) {
                //用户存在
                return -1;
            }
            //判断邮箱
            if (user1.getEmail().equals(user.getEmail())) {
                //邮箱已注册
                return -2;
            }
        }
        //将用户添加到容器中
        userList.add(user);
        //注册成功
        return 1;
    }

    @Override
    public User login(String username, String password) {
        for (User user : userList) {
            if (user.getUsername().equals(username)
                    && user.getPassword().equals(password)) {
                //已经找到该用户
                return user;
            }
        }
        //没找到
        return null;
    }

    @Override
    public int sendEmailByUserName(String username) {
        return 0;
    }

    @Override
    public int updatePassword(String username, String newPassword) {
        return 0;
    }

    @Override
    public int updateHeadr(String username, String header) {
        return 0;
    }

    @Override
    public int addHappyBean(Integer uid, Integer happyBean) {
        return 0;
    }
}
